<script setup lang="ts">
import { Router } from "@/utils/router";
import GuiderItem from "../components/guider-item.vue";
import { get_famous_guiderlist } from "@/package/famous-talk/api/guider";
import ScrollList from "@/components/list/scroll-list.vue";
import { my_data } from "../../api/guider";
import { reactive, provide, ref } from "vue";
import { Account } from "@/utils/account";
import { useShare } from "@/hooks/share";
import { AppData } from "@/utils/app";
import PopupModal from "@/components/popup/modal.vue";
import { onLoad } from "@dcloudio/uni-app";
import { useQuery } from "@/hooks/init";
const popupModal = ref<InstanceType<typeof PopupModal>>();
onLoad((options) => {
  useQuery(options as MiniApp.AppLaunchOption, () => {});
});
const { onShareAppMessage, onShareTimeline, shareOption } = useShare(
  "",
  (e) => {
    if (e.from === "button") {
      const itemData = data.value.filter(
        (item: any) => item.id == e.target.dataset.id
      );
      if (itemData && itemData.length) {
        const data: any = itemData[0];
        shareOption.title = data.title;
        shareOption.path = `package/famous-talk/pages/detail/index?id=${e.target.dataset.id}`;
        shareOption.imageUrl = data.pic_url;
      }
    }
  }
);
const likeConfig = reactive({
  guider_interview_like: [],
  guider_interview_favourite: [],
});
const getConfig = () => {
  //名导访谈首页 点赞 收藏
  return my_data("guider_interview_like,guider_interview_favourite").then(
    (res) => {
      likeConfig.guider_interview_like = res.guider_interview_like;
      likeConfig.guider_interview_favourite = res.guider_interview_favourite;
    }
  );
};
const istoLogin = (oprate: () => {}) => {
  const fn = () => {
    reflash();
    Router.navigateBack();
  };
  Account.checkLogin((isLogin) => {
    isLogin ? fn() : oprate();
  });
};
provide("likeConfig", { likeConfig, getConfig, onShareAppMessage, istoLogin });
Account.isLogin && getConfig();
const pageShow = ref(true);
const reflash = () => {
  getConfig();
  pageShow.value = false;
  setTimeout(() => {
    pageShow.value = true;
  });
};
const data = ref([]);
const getList = (e: any) => {
  data.value = e;
};
</script>
<template>
  <ScrollList :api="get_famous_guiderlist" :query="{type:1}" v-if="pageShow" @getList="getList">
    <template #default="{ list,reloadList }">
      <GuiderItem v-for="item in list" :key="item.id" :data="item" :reloadList="reloadList" />
    </template>
  </ScrollList>
  
  <PopupModal ref="popupModal" />
</template>

<style lang="scss">
</style>
